package org.harsh.transmission.common;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.Arrays;
import org.harsh.common.Config;

/**
 * Created by liuhaibo on 2024/6/12.
 */
@Slf4j
@AllArgsConstructor
@Data
@Deprecated
public class NettyMsg {
    private NettyMsgHead msgHead;
    private byte[] msg;

    public NettyMsg(Integer msgTypeCode, byte[] msg) {
        this.msg = msg;
        this.msgHead = new NettyMsgHead(msgTypeCode);
    }

    public NettyMsg(Integer msgTypeCode, String data) {
        this.msg = data.getBytes(Config.DEFAULT_CHARSET);
        this.msgHead = new NettyMsgHead(msgTypeCode);
    }

    public ByteBuf buildNettyMsg(){
        return Unpooled.wrappedBuffer(msgHead.buildNettyMsgHead(), msg);
    }

    public byte[] buildByteArray() {
        byte[] head = msgHead.buildNettyMsgHead();
        return Arrays.concatenate(head, msg);
    }
}
